/**

This file is part of MaCI/GIMnet.

MaCI/GIMnet is free software: you can redistribute it and/or modify it 
under the terms of the GNU Lesser General Public License as published 
by the Free Software Foundation, either version 3 of the License, or 
(at your option) any later version.

MaCI/GIMnet is distributed in the hope that it will be useful, but WITHOUT 
ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or 
FITNESS FOR A PARTICULAR PURPOSE.  See the GNU Lesser General Public 
License for more details.

You should have received a copy of the GNU Lesser General Public 
License along with GIMnet. (See COPYING.LESSER) If not, see 
<http://www.gnu.org/licenses/>.

**/
#include <stdio.h>
#include <stdlib.h>
#include <math.h>
#include <vector>
#include <map>
#include <inttypes.h>

using namespace std;


/** 
* A storage for representing sparce spatial data in a discrete manner
* This is mostly for visualization puropses
* Think this as a cube of size (double sizeX, double sizeY, double sizeZ), which 
* is discretized according to resolution. However, the storage only contains 
* the points that are added (points within resolution form one point).
**/ 

namespace lnm{
	struct TCoord3D{
		double x;
		double y;
		double z;
		TCoord3D(){
			set(0,0,0);
		}
		TCoord3D(double _x, double _y, double _z ){
			set(_x,_y,_z);
		}
		
		void set(double _x, double _y, double _z ){
			x = _x;
			y = _y;
			z = _z;
		}
	
	};

	struct RGB{
		unsigned char r;
		unsigned char g;
		unsigned char b;
		
		RGB(){
			set(0,0,0);
		}
		
		RGB(unsigned char R, unsigned char G, unsigned char B){
			set(R,G,B);
		}
		
		void set(unsigned char R, unsigned char G, unsigned char B){
			r=R;
			g=G;
			b=B;
		}
		
	};
};


class C3DPointStorage{
	public:
		/**
		* Constructor
		* @param sizeX maximum size of a cube in X coordinates [m] (max value ==)
		* @param sizeY	
		* @param sizeZ
		* @param resolution the resolution of the data
		**/
		C3DPointStorage(double sizeX, double sizeY, double sizeZ, double resolution);
		
		
		bool indexToCoord(uint64_t index, lnm::TCoord3D &coord);
		bool coordToIndex(lnm::TCoord3D &coord, uint64_t &index);
		
		bool setCoordPoint(lnm::TCoord3D &coord, lnm::RGB color);
		bool save(const char *fname);
		map<uint64_t, lnm::RGB> points;
		
	private:
			double sx;
			double sy;
			double sz;
			double reso;
			uint64_t Nx;
			uint64_t Ny;
			uint64_t Nz;


};